package com.mgq.design.chainofresponsibility.c1;

/**
 * <b>功能：</b>抽象父类<br>
 * <b>Copyright TCSL</b>
 * <li>版本&nbsp;&nbsp;&nbsp;&nbsp;修改日期&nbsp;&nbsp;&nbsp;&nbsp;部　　门&nbsp;&nbsp;&nbsp;&nbsp;作　者&nbsp;&nbsp;&nbsp;&nbsp;变更内容</li><hr>
 * <li>v1.0&nbsp;&nbsp;&nbsp;&nbsp;20220425&nbsp;&nbsp;营业后台&nbsp;&nbsp;&nbsp;&nbsp;马广奇&nbsp;&nbsp;&nbsp;&nbsp;创建类</li>
 * <br><br>
 *
 * @author 马广奇
 * @version 2022-04-25 17:09
 */
public abstract class AbstractLogger {
    public static int DEBUG = 0;
    public static int INFO = 1;
    public static int WARN = 2;
    public static int ERROR = 3;
    //责任链中的下一个元素
    protected AbstractLogger nextLogger;

    protected int level;

    public void setNextLogger(AbstractLogger nextLogger) {
        this.nextLogger = nextLogger;
    }

    public void logMessage(int logLevel, String message) {
        if (this.level <= logLevel) {
            write(message);
        }
        if (this.nextLogger != null) {
            nextLogger.logMessage(logLevel, message);
        }
    }

    /**
     *写日志的抽象方法
     */
    abstract void write(String message);
}
